<template>
  <div class="flex">
    <div class="tableManage w-100%">
      <ContentWrap>
        <!-- 搜索区域 -->
        <!-- <div class="search-form">
          <Search
            :schema="allSchemas.searchSchema"
            @reset="setSearchParams"
            @search="setSearchParams"
          />
        </div>

        <ElDivider /> -->

        <!-- 数据表格 -->
        <Table
          v-model:current-page="currentPage"
          v-model:page-size="pageSize"
          :columns="allSchemas.tableColumns"
          :data="dataList"
          :loading="loading"
          @register="tableRegister"
          :pagination="{ total }"
        />
      </ContentWrap>
    </div>

    <!-- 新增/编辑/查看对话框 -->
    <Dialog width="65%" v-model="dialogVisible" :title="dialogTitle">


      <!-- 详情组件（查看时显示） -->
      <Detail
        v-if="actionType === 'detail'"
        :detail-schema="allSchemas.detailSchema"
        :current-row="currentRow"
      />

      <!-- 对话框底部按钮 -->
      <template #footer>
        <BaseButton @click="dialogVisible = false">关闭</BaseButton>
      </template>
    </Dialog>
  </div>
</template>

<script setup lang="tsx">
import { directAxios } from "@/axios/index";
import {
  ref,
  unref,
  reactive,
  watch,
  computed,
  onMounted,
  defineProps,
  withDefaults,
  ComponentRef,
} from "vue";
import { ContentWrap } from "@/components/ContentWrap";
import { Table } from "@/components/Table";

import { useTable } from "@/hooks/web/useTable";
import { Search } from "@/components/Search";
import Write from "./components/Write.vue";
import { useValidator } from "@/hooks/web/useValidator";
import Detail from "./components/iComponentsDetail.vue";
import { Dialog } from "@/components/Dialog";
import { CrudSchema, useCrudSchemas } from "@/hooks/web/useCrudSchemas";
import { BaseButton } from "@/components/Button";
import { useDeviceTreeStore } from "@/store/modules/deviceTreeStore";
import { useDictionaryStore } from "@/store/modules/dictionaryStore";
import {  View } from "@element-plus/icons-vue";

// ============ 初始化和Store定义 ============
const { required } = useValidator();
const deviceTreeStore = useDeviceTreeStore();
const dictionaryStore = useDictionaryStore();






// 当前节点相关

interface CurrentNodeTask {
  deviceCode?: string;
  deviceName?: string;
  missionCode?: string;
  // 根据实际需要添加其他属性
}
interface Props {
  currentNodeTask?: CurrentNodeTask;
  type?: string;
}
// 使用 withDefaults 设置默认值
const props = withDefaults(defineProps<Props>(), {
  currentNodeTask: () => ({}),
  type: undefined
});
// 使用计算属性确保值的安全性
const safeCurrentNodeTask = computed(() =>
  props.currentNodeTask && typeof props.currentNodeTask === 'object'
    ? props.currentNodeTask
    : {}
);
const deviceCode = ref(safeCurrentNodeTask.value.deviceCode ?? '');
const currentNodeName = ref(safeCurrentNodeTask.value.deviceName ?? '');
const missionCode = ref(safeCurrentNodeTask.value.missionCode ?? '');



// 表格相关状态
const { tableRegister, tableState, tableMethods } = useTable({
  /**
   * 获取进口元器件表格数据的API
   */
  fetchDataApi: async () => {
    const { pageSize, currentPage } = tableState;

    if (!deviceCode.value) {
      return {
        list: [],
        total: 0,
      };
    }
     const collectorUserCode = localStorage.getItem("collectorUserCode");

    const res = await "/cImportedComponents/page".get({
      deviceCode: deviceCode.value,
      pageNum: unref(currentPage),
      pageSize: unref(pageSize),
      ...unref(searchParams),
      missionCode: missionCode.value,
      isLockTask:1,
        createby: collectorUserCode || "",
    });
    return {
      list: res.data.records || [],
      total: res.data.total || 0,
    };
  },
});

const { total, loading, dataList, pageSize, currentPage } = tableState;
const { getList } = tableMethods;
// 监听 props 变化
watch(
  () => props.currentNodeTask,
  (newVal, oldVal) => {
    try {
      console.log(newVal, oldVal, "currentNodeTask");
      deviceCode.value = newVal?.deviceCode ?? '';
      currentNodeName.value = newVal?.deviceName ?? '';
      missionCode.value = newVal?.missionCode ?? '';
      // 只有在有设备代码时才调用 getList
      if (newVal?.deviceCode && newVal?.missionCode) {
        getList();
      }
    } catch (error) {
      console.error('Error in currentNodeTask watcher:', error);
      // ElMessage.error('数据加载失败');
    }
  },
  { immediate: true } // 添加 immediate 确保初始执行
);
// 搜索参数
const searchParams = ref({ classificationCode: "" });

// 对话框相关状态
const dialogVisible = ref(false);
const dialogTitle = ref("");
const currentRow = ref();
const actionType = ref("");



// ============ 字典数据计算属性 ============

/**
 * 元器件分类选项
 */
const classificationOptions = computed(() => {
  return dictionaryStore.dictionaries.get(
    dictionaryStore.DICTIONARY_TYPES.COM_CLASSIFICATION
  ) || [];
});

/**
 * 安全等级颜色选项
 */
const safetyLevelOptions = computed(() => {
  return dictionaryStore.dictionaries.get(
    dictionaryStore.DICTIONARY_TYPES.SAFETY_LEVEL_COLOR
  ) || [];
});

/**
 * 对外依存度选项
 */
const dependencyOptions = computed(() => {
  return dictionaryStore.dictionaries.get(
    dictionaryStore.DICTIONARY_TYPES.EXTERNAL_DEPENDENCE
  ) || [];
});

/**
 * 必要性等级选项
 */
const necessityOptions = computed(() => {
  return dictionaryStore.dictionaries.get(
    dictionaryStore.DICTIONARY_TYPES.NECESSITY_LEVEL
  ) || [];
});

/**
 * 是否核关高选项
 */
const isHighlyCriticalOptions = computed(() => {
  return dictionaryStore.dictionaries.get(
    dictionaryStore.DICTIONARY_TYPES.YORN
  ) || [];
});

/**
 * 获取渠道选项
 */
const acquisitionChannelOptions = computed(() => {
  return dictionaryStore.dictionaries.get(
    dictionaryStore.DICTIONARY_TYPES.ACQUISITION_CHANNEL
  ) || [];
});

/**
 * 解决方案计划选项
 */
const solutionPlanOptions = computed(() => {
  return dictionaryStore.dictionaries.get(
    dictionaryStore.DICTIONARY_TYPES.SOLUTION_PLAN
  ) || [];
});

// ============ 类别选择处理 ============

/**
 * 获取级联选择器选中对象的工具函数
 * @param val 选中的值数组
 * @param opt 选项数组
 * @returns 选中的选项对象数组
 */
const getCascaderObj = (val, opt) => {
  return val.map(function (value, index, array) {
    for (var itm of opt) {
      if (itm.code == value) {
        opt = itm.children;
        return itm;
      }
    }
    return null;
  });
};

/**
 * 处理类别选择变化
 * @param value 选中的值数组
 */
const handleCategoryChange = (value) => {
  console.log("类别选择变化:", value);

  const selectedOptions = getCascaderObj(
    value,
    dictionaryStore.dictionaries.get(dictionaryStore.DICTIONARY_TYPES.COM_CLASSIFICATION)
  );

  if (!currentRow.value) {
    currentRow.value = {};
  }

  // 清空之前的分类数据
  currentRow.value.classification1 = "";
  currentRow.value.classification2 = "";
  currentRow.value.classification3 = "";
  currentRow.value.classificationCode = "";
  currentRow.value.category = value;

  // 设置分类代码和各级分类名称
  if (selectedOptions.length > 0) {
    currentRow.value.classificationCode = selectedOptions[selectedOptions.length - 1].code;
    currentRow.value.classification1 = selectedOptions[0]?.text || "";
  }
  if (selectedOptions.length > 1) {
    currentRow.value.classification2 = selectedOptions[1]?.text || "";
  }
  if (selectedOptions.length > 2) {
    currentRow.value.classification3 = selectedOptions[2]?.text || "";
  }
};
// 在子组件中添加这个方法
const findDeviceNameByCode = (deviceCode: string) => {
  console.log('deviceCode', deviceCode,props.currentNodeTask);

  if (!deviceCode || !props.currentNodeTask) return '';

  // 递归查找设备名称
  const findInTree = (nodes: any[]): string => {
    for (const node of nodes) {
      if (node.deviceCode === deviceCode) {
        return node.deviceName || '';
      }
      if (node.children && node.children.length > 0) {
        const result = findInTree(node.children);
        if (result) return result;
      }
    }
    return '';
  };

  return findInTree([props.currentNodeTask]);
};
// ============ CRUD表结构配置 ============

/**
 * 进口元器件管理表结构配置
 */
const crudSchemas = reactive<CrudSchema[]>([
  {
    field: "selection",
    width: 55,
    search: { hidden: true },
    form: { hidden: true },
    detail: { hidden: true },
    table: { type: "selection", hidden: true },
  },
  {
    field: "index",
    label: "序号",
    width: 55,
    form: { hidden: true },
    search: { hidden: true },
    detail: { hidden: true },
    table: { type: "index" },
  },
  {
    field: "account",
    label: "所属设备",
    width: 90,
    search: { hidden: true },
    form: {
      component: "Input",
      value: currentNodeName.value,
      componentProps: {
        placeholder: "请输入所属设备",
        disabled: true,
      },
    },
    table: { hidden: true },
  },
  {
    field: "classificationCode",
    label: "分类代码",
    width: 100,
    form: {
      componentProps: {
        placeholder: "请输入分类代码",
        disabled: true,
      },
      formItemProps: { rules: [required()] },
    },
    search: {
      component: "Input",
      label: "",
      hidden: true,
      componentProps: { placeholder: "分类代码" },
    },
  },
  {
    field: "category",
    label: "类别",
    width: 250,
    search: {
      component: "Cascader",
      componentProps: {
        placeholder: "类别",
        options: classificationOptions,
        filterable: true,
        props: {
          checkStrictly: false,
          emitPath: true,
          label: "text",
          value: "code",
        },
      },
    },
    form: {
      component: "Cascader",

      formItemProps: {
        rules: [{ required: true, message: "请选择类别" }],
      },
      componentProps: {
        placeholder: "请选择类别",
        filterable: true,
        options: classificationOptions,
        props: {
          checkStrictly: false,
          emitPath: true,
          label: "text",
          value: "code",
        },
        onChange: handleCategoryChange,
      },
    },
    detail: { hidden: true },
    table: {
         formatter: (row: any) => {
        // 组合分类字段，用 > 分隔，空值用 / 代替
        const parts = [
          row.classification1 || "/",
          row.classification2 || "/",
          row.classification3 || "/",
        ];
         return parts.join(" > ");
      },
    },
  },
  {
    field: "classification1",
    label: "一级类别",
    width: 90,
    search: { hidden: true },
    form: { hidden: true },
    table: { hidden: true },
  },
  {
    field: "classification2",
    label: "二级类别",
    width: 90,
    search: { hidden: true },
    form: { hidden: true },
    table: { hidden: true },
  },
  {
    field: "classification3",
    label: "三级类别",
    width: 90,
    search: { hidden: true },
    form: { hidden: true },
    table: { hidden: true },
  },
  {
    field: "componentName",
    label: "元器件名称",
    width: 150,
    search: {
      component: "Input",
      label: "",
      hidden: false,
      componentProps: { placeholder: "元器件名称" },
    },
    form: {
      component: "Input",
      formItemProps: {
        rules: [
          { required: true, message: "请输入元器件名称" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入元器件名称" },
        ],
      },
      componentProps: { placeholder: "请输入元器件名称" },
    },
  },
  {
    field: "modelSpecification",
    label: "型号规格",
    width: 120,
    search: {
      component: "Input",
      label: "",
      hidden: false,
      componentProps: { placeholder: "型号规格" },
    },
    form: {
      component: "Input",
      formItemProps: {
        rules: [
          { required: true, message: "请输入型号规格" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入型号规格" },
        ],
      },
      componentProps: { placeholder: "请输入型号规格" },
    },
  },

  {
    field: "manufacturer",
    label: "生产厂商",
    width: 150,
    search: {
      component: "Input",
      label: "",
      hidden: false,
      componentProps: { placeholder: "生产厂商" },
    },
    form: {
      component: "Input",
      formItemProps: {
        rules: [
          { required: true, message: "请输入生产厂商" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入生产厂商" },
        ],
      },
      componentProps: { placeholder: "请输入生产厂商" },
    },
  },
     {
    field: "countryRegion",
    label: "国别地区",
    width: 150,
    search: { hidden: true },
    form: {
      component: "Input",
      formItemProps: {
        rules: [
          { required: true, message: "请输入国别地区" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入国别地区" },
        ],
      },
      componentProps: { placeholder: "请输入国别地区" },
      colProps: { span: 24 },
    },
    detail: { span: 24 },
  },
  {
    field: "qualityLevel",
    label: "质量等级",
    width: 80,
    search: {
      hidden: false,
      componentProps: { placeholder: "质量等级" },
    },
    form: {
      hidden: false,
      formItemProps: {
        rules: [
          { required: true, message: "请输入质量等级" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入质量等级" },
        ],
      },
    },
  },
  {
    field: "packagingType",
    label: "封装形式",
    search: { hidden: true },
    form: {
      component: "Input",
      formItemProps: {
        rules: [
          { required: true, message: "请输入封装形式" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入封装形式" },
        ],
      },
      componentProps: { placeholder: "请输入封装形式" },
    },
    table: { hidden: true },
  },
    {
    field: "safetyLevelColor",
    label: "安全等级颜色",
    width: 110,
    search: {
      hidden: false,
      component: "Select",
      componentProps: {
        placeholder: "安全等级颜色",
        options: safetyLevelOptions,
      },
    },
    form: {
      hidden: false,
      component: "Select",
      value: [],
      componentProps: {
        placeholder: "安全等级颜色",
        options: safetyLevelOptions,
      },
      formItemProps: {
        rules: [{ required: true, message: "请选择安全等级颜色" }],
      },
    },
  },
  {
    field: "suggestedSafetyColor",
    label: "建议安全等级颜色",
    width: 80,
    search: { hidden: true },
    form: {
      component: "Select",
      formItemProps: {
        rules: [
          { required: true, message: "请选择建议安全等级颜色" },

        ],
      },
      componentProps: { placeholder: "请选择建议安全等级颜色", options: safetyLevelOptions, },
    },
    detail: { span: 12 },
    table: { hidden: true },
  },
  {
    field: "coreIndicators",
    label: "核心指标",
    width: 90,
    search: { hidden: true },
    table: { hidden: true },
    form: {
      component: "Input",
      formItemProps: {
        rules: [
          { required: true, message: "请输入核心指标" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入核心指标" },
        ],
      },
      colProps: { span: 24 },
    },
    detail: { span: 24 },
  },
  {
    field: "externalDependence",
    label: "对外依存度",
    width: 90,
    search: { hidden: true },
    table: { hidden: true },
    form: {
      component: "Select",
      value: "",
      componentProps: {
        placeholder: "对外依存度",
        options: dependencyOptions,
      },
      formItemProps: {
        rules: [{ required: true, message: "请选择对外依存度" }],
      },
    },
  },
  {
    field: "riskAnalysis",
    label: "风险分析",
    width: 90,
    table: { hidden: true },
    search: {
      component: "Input",
      label: "风险分析",
      hidden: true,
      componentProps: { placeholder: "风险分析" },
    },
    form: {
      component: "Input",
      formItemProps: {
        rules: [
          { required: true, message: "请输入风险分析" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入风险分析" },
        ],
      },
    },
  },
  {
    field: "necessityLevel",
    label: "必要性",
    width: 90,
    search: { hidden: true },
    table: { hidden: true },
    form: {
      component: "Select",
      value: "",
      componentProps: {
        placeholder: "请选择必要性",
        options: necessityOptions,
      },
      formItemProps: {
        rules: [{ required: true, message: "请选择必要性" }],
      },
    },
  },

  {
    field: "quantityPerDevice",
    label: "单个设备使用该产品数量",
    width: 90,
    search: { hidden: true },
    table: { hidden: true },
    form: {
      component: "Input",
      formItemProps: {
        rules: [
          { required: true, message: "请输入使用数量" },
          {
            validator: (rule, value, callback) => {
              if (value < 0) {
                return callback(new Error("输入值不能低于 0"));
              }
              callback();
            },
          },
        ],
      },
      componentProps: {
        type: "number",
        placeholder: "请输入使用数量",
        min: 0,
      },
    },
  },

  {
    field: "isCoreComponent",
    label: "是否核心关键元器件",
    width: 150,
    form: {
      component: "Select",
      value: "",
      componentProps: {
        placeholder: "请选择是否核心关键元器件",
        options: isHighlyCriticalOptions,
      },
      formItemProps: {
        rules: [{ required: true, message: "请选择是否核心关键元器件" }],
      },
    },
    search: {
      component: "Select",
      label: "是否核心关键元器件",
      hidden: false,
      componentProps: {
        placeholder: "是否核心关键元器件",
        options: isHighlyCriticalOptions,
      },
    },
  },
  {
    field: "referencePrice",
    label: "参考价格(元)",
    width: 120,
    search: { hidden: true },
    form: {
      component: "Input",
      formItemProps: {
        rules: [
          { required: true, message: "请输入参考价格" },
          {
            validator: (rule, value, callback) => {
              if (value < 0) {
                return callback(new Error("输入值不能低于 0"));
              }
              callback();
            },
          },
        ],
      },
      componentProps: {
        type: "number",
        placeholder: "请输入参考价格",
        min: 0,
      },
    },
  },
  {
    field: "supplyCycle",
    label: "供货周期(周)",
    width: 120,
    search: { hidden: true },
    form: {
      component: "Input",
      formItemProps: {
        rules: [
          { required: true, message: "请输入供货周期" },
          {
            validator: (rule, value, callback) => {
              if (value < 0) {
                return callback(new Error("输入值不能低于 0"));
              }
              callback();
            },
          },
        ],
      },
      componentProps: {
        type: "number",
        placeholder: "请输入供货周期",
        min: 0,
      },
    },
  },

  {
    field: "acquisitionChannel",
    label: "获取渠道",
    width: 90,
    search: { hidden: true },
    table: { hidden: true },
    form: {
      component: "Select",
      value: "",
      componentProps: {
        placeholder: "请选择获取渠道",
        options: acquisitionChannelOptions,
      },
    },
    detail: { span: 12 },
  },
  {
    field: "solutionPlan",
    label: "解决方案",
    width: 90,
    search: { hidden: true },
    table: { hidden: true },
    form: {
      component: "Select",
      value: "",
      formItemProps: {
        rules: [{ required: true, message: "请选择解决方案" }],
      },
      componentProps: {
        placeholder: "请选择解决方案",
        options: solutionPlanOptions,
      },
    },
    detail: { span: 12 },
  },
  {
    field: "alternativeSpec",
    label: "可替代产品规格",
    width: 90,
    search: { hidden: true },
    table: { hidden: true },
    form: {
      component: "Input",
      colProps: { span: 12 },
      formItemProps: {
        rules: [
          { required: true, message: "请输入可替代产品规格" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入可替代产品规格" },
        ],
      },
      componentProps: { placeholder: "请输入可替代产品规格" },
    },
    detail: { span: 12 },
  },
  {
    field: "alternativeQualityLevel",
    label: "可替代产品质量等级",
    width: 90,
    search: { hidden: true },
    table: { hidden: true },
    form: {
      component: "Input",
      colProps: { span: 12 },
      formItemProps: {
        rules: [
          { required: true, message: "请输入可替代产品质量等级" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入可替代产品质量等级" },
        ],
      },
      componentProps: { placeholder: "请输入可替代产品质量等级" },
    },
    detail: { span: 12 },
  },
  {
    field: "alternativeManufacturer",
    label: "可替代产品厂商",
    width: 90,
    search: { hidden: true },
    table: { hidden: true },
    form: {
      component: "Input",
      formItemProps: {
        rules: [
          { required: true, message: "请输入可替代产品厂商" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入可替代产品厂商" },
        ],
      },
      colProps: { span: 12 },
      componentProps: { placeholder: "请输入可替代产品厂商" },
    },
    detail: { span: 12 },
  },

  {
    field: "completionForm",
    label: "完成形式",
    width: 90,
    search: { hidden: true },
    table: { hidden: true },
    form: {
      component: "Input",
      colProps: { span: 12 },
      formItemProps: {
        rules: [
          { required: true, message: "请输入完成形式" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入完成形式" },
        ],
      },
      componentProps: { placeholder: "请输入完成形式" },
    },
    detail: { span: 12 },
  },
  {
    field: "expectedCompletionTime",
    label: "预计完成时间",
    width: 90,
    search: { hidden: true },
    table: { hidden: true },
    form: {
      component: "DatePicker",
      colProps: { span: 12 },
      formItemProps: {
        rules: [{ required: true, message: "请选择预计完成时间" }],
      },
      componentProps: {
        type: "date",
        placeholder: "请选择预计完成时间",
      },
    },
    detail: { span: 12 },
  },
  {
    field: "personInCharge",
    label: "负责人",
    width: 80,
    search: { hidden: true },
    form: {
      component: "Input",
      formItemProps: {
        rules: [
          { required: true, message: "请输入负责人" },
          { pattern: /^(?!\s*$)(?!\/+$).+$/, message: "请输入负责人" },
        ],
      },
      componentProps: { placeholder: "请输入负责人" },
    },
  },
  {
    field: "contactInfo",
    label: "联系方式",
    width: 120,
    search: { hidden: true },
    form: {
      component: "Input",
      componentProps: { placeholder: "请输入联系方式" },
      formItemProps: {
        rules: [
          { required: true, message: "请输入联系方式" },
          { pattern: /^[0-9]{11}$/, message: "请输入正确的联系方式" },
        ],
      },
      colProps: { span: 12 },
    },
  },
  {
    field: "remarks",
    label: "备注",
    width: 90,
    search: { hidden: true },
    detail: { span: 24 },
    form: {
      component: "Input",
      componentProps: {
        type: "textarea",
        rows: 3,
        placeholder: "请输入备注信息",
      },
      colProps: { span: 24 },
    },
    table: { hidden: true },
  },

  {
    field: "action",
    label: "操作",
    fixed: "right",
    width: 80,
    form: { hidden: true },
    detail: { hidden: true },
    search: { hidden: true },
    table: {

      slots: {
        default: (data: any) => {
          const row = data.row;
          return (
            <>
              <div style="display:flex;color: var(--el-color-primary)">

                <div class="flex-1 cursor-pointer" onClick={() => action(row, "detail")}>
                  <el-icon><View /></el-icon>查看
                </div>

              </div>
            </>
          );
        },
      },
    },
  },
]);

const { allSchemas } = useCrudSchemas(crudSchemas);



// ============ 方法定义 ============

/**
 * 设置搜索参数并刷新表格
 * @param params 搜索参数
 */
const setSearchParams = (params: any) => {
  currentPage.value = 1;
  searchParams.value = params;
  // 处理级联选择器的值（取最后一级）
    searchParams.value.classificationCode =
    params.category?.[params.category.length - 1] || "";

  getList();
};




/**
 * 行操作处理（编辑/查看）
 * @param row 行数据
 * @param type 操作类型：'edit' | 'detail'
 */
const action = (row: any, type: string) => {
  dialogTitle.value = type === "edit" ? "编辑" : "查看";
  actionType.value = type;
    (row.classificationCode===undefined||row.classificationCode==''||row.classificationCode==null)?row.classificationCode="":row.classificationCode
  const data =row.classificationCode.length==8?[
      row.classificationCode.slice(0, 4)||"",
      row.classificationCode.slice(0, 6)||"",
      row.classificationCode||"",
    ]:row.classificationCode.length==6?[
      row.classificationCode.slice(0, 4)||"",
      row.classificationCode.slice(0, 6)||"",

    ]:[ row.classificationCode.slice(0, 4)||"",]
     // 根据 deviceCode 查找设备名称
  const deviceName = findDeviceNameByCode(row.deviceCode);
  currentRow.value = {
    ...row,
    category: data,
     account: deviceName, // 使用查找到的设备名称保所属设备字段有值
  };
  dialogVisible.value = true;
};




// ============ 生命周期 ============
onMounted(async () => {
  // 检查是否有有效数据
   if (safeCurrentNodeTask.value.deviceCode && safeCurrentNodeTask.value.missionCode) {
    getList();
  }
});
</script>

<style scoped lang="less">
.el-card {
  // 卡片样式可以在这里定义
}

.operIcon {
  width: 20px !important;
}

:deep(.el-divider--horizontal) {
  margin: 5px 0 15px 0;
}

.mb-10px {
  display: flex;
}

.opBtn-upload {
  display: inline-block;
  margin: 0 12px;
}
:deep(.el-card__body ){
  padding: 10px  0 !important;
}
</style>
